using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace MacViet.DataBaseAPI
{
    /// <summary>
    /// Description: Concrete DataProvider for table Payment_Type. Provides atomic API functions.
    /// Author:  phong.huynh
    /// Created: 13/08/2010 9:56:28 SA
    /// </summary>
    public class PAYMENT_TYPEDataAPI
    {
        private SQLHelper _dbTool = new SQLHelper();


        // ************************************
        // Implements function getByColumnName
        // ************************************

        public DataTable getByPTYP_ID(System.Int32 PTYP_ID)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENT_TYPEDTO._PTYP_ID, PTYP_ID) };
            return _dbTool.executeReader("SP_SEL_PAYMENT_TYPE_getByPTYP_ID", parm);
        }



        public DataTable getByPTYP_NAME(System.String PTYP_NAME)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENT_TYPEDTO._PTYP_NAME, PTYP_NAME) };
            return _dbTool.executeReader("SP_SEL_PAYMENT_TYPE_getByPTYP_NAME", parm);
        }



        // *************************************************
        // Implement function getAll/getByDynamicCondition
        // *************************************************

        public DataTable getAll()
        {
            return _dbTool.executeReader("SP_SEL_PAYMENT_TYPE_getAll");
        }


        public DataTable getPaymentType(System.Int32 ACC_ID)
        {
            SqlParameter[] parm = { new SqlParameter(ACCOUNTSDTO._ACC_ID, ACC_ID) };
            return _dbTool.executeReader("SP_PAYMENT_TYPE",parm);
        }



        // ********************************************************
        // Implement function getByPrimaryKeys / getByForeignKeys
        // In case table have composite primary/foreign keys
        // ********************************************************

        public DataTable getByPrimaryKeys(System.Int32 PTYP_ID)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENT_TYPEDTO._PTYP_ID, PTYP_ID) };
            return _dbTool.executeReader("SP_SEL_PAYMENT_TYPE_getByPrimaryKeys", parm);
        }

        public bool insertPAYMENT_TYPE(System.String PTYP_NAME)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENT_TYPEDTO._PTYP_ID,1),
                                    new SqlParameter(PAYMENT_TYPEDTO._PTYP_NAME,PTYP_NAME)};
            int effectedRows = _dbTool.ExecuteNoneQuery("SP_INS_PAYMENT_TYPE_values", parm);

            return (effectedRows == 1);
        }


        ///<summary>		
        /// Thu+.c hie^.n ca^u le^.nh update du+.a tre^n kho'a chi'nh
        ///</summary>

        public bool updatePAYMENT_TYPE(System.Int32 PTYP_ID, System.String PTYP_NAME)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENT_TYPEDTO._PTYP_ID,PTYP_ID),
                                    new SqlParameter(PAYMENT_TYPEDTO._PTYP_NAME,PTYP_NAME)};
            int affectRows = _dbTool.ExecuteNoneQuery("SP_UDP_PAYMENT_TYPE_update", parm);

            return affectRows == 1;
        }

        // ********************************************************************************
        // Implementation of deleteAll/deteleByForeignKeys/deleteByPrimaryKeys function		
        // ********************************************************************************

        // return number of deleted rows		
        public int deleteAll()
        {
            return _dbTool.ExecuteNoneQuery("SP_DEL_PAYMENT_TYPE_deleteAll");
        }

        // return number of deleted rows
        public int deleteByPrimaryKeys(System.Int32 PTYP_ID)
        {
            SqlParameter[] parm = { new SqlParameter(PAYMENT_TYPEDTO._PTYP_ID, 1) };
            return _dbTool.ExecuteNoneQuery("SP_DEL_PAYMENT_TYPE_deleteByPrimaryKeys", parm);
        }

    }
}